export default function useLoadFileIcon() {
  function loadFileIcon(tableDataItem: ITableDataItem) {
    let result: any

    // 如果是目录,直接加载目录图标
    if (tableDataItem.type === 'folder') {
      result = () => import(`../icon/FolderIcon.vue`)
    } else {
      // 按文件解析,分析文件后缀
      const ext = tableDataItem.original.ext
      if (ext) {
        if (['txt', 'log'].includes(ext)) {
          result = () => import(`../icon/TxtFileIcon.vue`)
        } else if (
          [
            'xls',
            'xlsx',
            'xlsm',
            'xlsb',
            'xlt',
            'xltm',
            'xlsm',
            'xla',
            'xlm',
            'xlw',
            'odc'
          ].includes(ext)
        ) {
          result = () => import(`../icon/XlsFileIcon.vue`)
        } else if (['ppt', 'pptx', 'pptm'].includes(ext)) {
          result = () => import(`../icon/PptFileIcon.vue`)
        } else if (
          [
            'avi',
            'mpg',
            'mpeg',
            'rm',
            'rmvb',
            'flv',
            'wmv',
            'mov',
            'mkv',
            'ASF',
            'M1V',
            'M2V',
            'MPE',
            'QT',
            'VOB',
            'RA',
            'RMJ',
            'RMS',
            'RAM',
            'mp4',
            'hls',
            'm3u8',
            'ogg',
            'asf',
            '3gp',
            'dat',
            'vob'
          ].includes(ext)
        ) {
          result = () => import(`../icon/VideoFileIcon.vue`)
        } else if (
          [
            'jpg',
            'gif',
            'png',
            'bmp',
            'tif',
            'tiff',
            'psd',
            'ico',
            'svg'
          ].includes(ext)
        ) {
          result = () => import(`../icon/ImageFileIcon.vue`)
        } else if (
          ['zip', 'rar', '7z', 'tar', 'gz', 'tar.gz', 'tgz'].includes(ext)
        ) {
          result = () => import(`../icon/ZipFileIcon.vue`)
        } else if (['lnk', 'pif', 'url'].includes(ext)) {
          result = () => import(`../icon/LinkFileIcon.vue`)
        } else if ('pdf' === ext) {
          result = () => import(`../icon/PdfFileIcon.vue`)
        } else if (
          ['doc', 'docx', 'dot', 'dotm', 'dotx', 'rtf'].includes(ext)
        ) {
          result = () => import(`../icon/WordFileIcon.vue`)
        } else if (
          [
            'mp3',
            'flac',
            'wav',
            'm4a',
            'mp2',
            'mp1',
            'aif',
            'aiff',
            'au',
            'ra',
            'ram',
            'mid',
            'rmi'
          ].includes(ext)
        ) {
          result = () => import(`../icon/MusicFileIcon.vue`)
        }
      }

      if (result === undefined) {
        // 未知类型
        result = () => import(`../icon/UnknownFileIcon.vue`)
      }
    }

    return result
  }

  return {
    loadFileIcon
  }
}
